import { useIntersectionObserver } from '@vueuse/core'
import defImg from '@/assets/images/200.png'
// 图片加载动画
import loadImg from '@/assets/images/load.gif'
export default {
  install (app) {
    // console.log('22222222', app)
    app.config.globalProperties.load = loadImg
    app.directive('ilazy', {
      mounted (el, binding) {
        // console.log('元素挂载了：', el, binding)
        const { stop } = useIntersectionObserver(
          el,
          ([{ isIntersecting }]) => {
            if (isIntersecting) {
              el.src = binding.value

              el.onerror = () => {
                el.src = defImg
              }
            }
            stop()
          }
        )
      }
    })
  }
}
